
    jQuery(document).ready(function() {


        $.backstretch([
            "assets/img/backgrounds/1.jpg"
            , "assets/img/backgrounds/2.jpg"
            , "assets/img/backgrounds/3.jpg"
        ], {duration: 3000, fade: 750});


        $('.links a.home').tooltip();
        $('.links a.blog').tooltip();

    })

//注册
function btnRegister() {
    var user_account = $('#user_account').val();
    var user_password = $('#user_password').val();
    var user_password1 = $('#user_password1').val();
    var user_phone = $('#user_phone').val();
    var code = $('#code').val();
    var code_phone = $('#code_phone').val();

    $("#user_account_label").html("用户名");
    $("#user_password_label").html("登录密码");
    $("#user_password1_label").html("确认密码");
    $("#user_phone_label").html("手机号码");
    $("#code_label").html("验证码");
    $("#code_phone_label").html("手机验证码");

    if (user_account == '' || !((/^[a-zA-Z][0-9a-zA-Z]{5,19}/).test(user_account))) {
        $("#user_account_label").html("<span style='color: red;'> -用户名格式不符号要求 </span>");
        return false;
    }
    if (!((/^[0-9a-zA-Z]{6,20}/).test(user_password))) {
        $("#user_password_label").html("<span style='color: red;'> -密码格式不符号要求 </span>");
        return false;
    }
    if (user_password1 != user_password) {
        $("#user_password1_label").html("<span style='color: red;'> -两次输入的密码不一样 </span>");
        return false;
    }
    if(!(/^1[3456789]\d{9}$/.test(user_phone))){
        $("#user_phone_label").html("<span style='color: red;'> -请输入正确的手机号码 </span>");
    }
    if(code==''){
        $("#code_label").html("<span style='color: red;'> -验证码不能为空 </span>");
    }
    if(code_phone==''){
        $("#code_phone_label").html("<span style='color: red;'> -手机验证码不能为空 </span>");
    }
    $.ajax({
        url:"/registerCheck",
        type:"post",
        data:{
            user_account:user_account,
            user_password:user_password,
            user_phone:user_phone,
            code:code,
            code_phone:code_phone
        },
        success:function (row) {
            btnImgCode();
            if(row==1){
                $("#user_account_label").html("<span style='color: red;'> -帐号已存在 </span>");
                return false;
            }
            if(row==2){
                $("#code_label").html("<span style='color: red;'> -验证码错误 </span>");
                return false;
            }
            if(row==3){
                $("#code_phone_label").html("<span style='color: red;'> -短信验证码错误 </span>");
                return false;
            }
            if(row==4){
                $("#user_phone_label").html("<span style='color: red;'> -该手机号已注册 </span>");
            }

            if(row==5){
                location.href="/login";
            }
        }
    })
}




// 更换验证码
function btnImgCode(){
    document.getElementById("imgCode").src="/getCode?"+Math.random();
}


window.onload = function ()
    {
        var btn = document.getElementById ('getCode_phone');
        btn.onclick = function () {
            //触发发送按钮,判断验证码
            var code = $('#code').val();
            $("#code_label").html("验证码");
            // 手机请求发送
            $.ajax({
                url:"/getCode_phone",
                type:"post",
                data:{
                    user_phone:$("#user_phone").val(),
                    code:code
                },
                success:function (info) {
                    if(info==1){
                        $("#code_label").html("<span style='color: red;'> -验证码错误或失效 </span>");
                        return false;
                    }
                    if(info==0){
                        $("#code_phone_label").html("<span style='color: red;'> -网络异常 </span>");
                        return false;
                    }
                    if(info==2){
                        $("#user_phone_label").html("<span style='color: red;'> -请输入正确的手机号码 </span>");
                        return false;
                    }
                    if(info==3){
                        btnCheck();
                    }

                }
            })
        }
    }
    function btnCheck() {

        var code = $("#getCode_phone");
        code.attr("disabled","disabled");
        setTimeout(function(){
            code.css("opacity","0.8");
        },1000)
        var time = 60;
        var set=setInterval(function(){
            code.val("("+--time+")秒后重新获取");
            code.css("background-color","#c1c1c1");
        }, 1000);
        setTimeout(function(){
            code.attr("disabled",false).val("重新获取验证码");
            clearInterval(set);
            code.css("background-color","#0088cc");
        }, 60000);

    }